// pages/fangzai/fangzai.js
const db = wx.cloud.database({});
const app = getApp()
Page({


  /**
   * 页面的初始数据
   */
  data: {
    Date: '',
    bindtap: app.globalData.bindtap,
    link: '',
    content: '',
    choose: '',
    idx: 0,
    color1: 'black',
    color2: 'black',
    color3: 'black',
    color4: 'black',
    color5: 'black',
  },

  navigateBack: function () {
    wx.navigateBack({
      delta: 1,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    getApp().globalData.bindtap = 1;
    var year = new Date().getFullYear() // 示例
    var month = new Date().getMonth() + 1
    var day = new Date().getDate()
    var choose = '气象水文灾害'
    Date: Date
    choose: choose
    this.setData({
      Date: year + '.' + month + '.' + day,
      choose: '气象水文灾害'
    })
    const db = wx.cloud.database({});
    const cont = db.collection('eas-qixiang');
    var content = app.globalData.content
    cont.skip(0)
      .limit(5).get({
        //如果查询成功的话
        success: res => {
          this.setData({
            list: res.data,
          })
        }
      })


  },
  qixiang1: function (e) {
    this.setData({
      color1: '#00A2FF',
      color2: 'black',
      color3: 'black',
      color4: 'black',
      color5: 'black',
    })
    const db = wx.cloud.database({});
    const cont = db.collection('eas-qixiang');
    var choose = '气象水文灾害'
    this.setData({
      choose: '气象水文灾害'
    })
    app.globalData.content = db.collection('eas-qixiang');
    cont.skip(0).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data,
        })
      }
    })
    let id = e.currentTarget.dataset.id;
    // console.log('每个index',index)
    this.setData({
      'idx': id
    })
    // console.log(id)
  },
  qixiang2: function () {
    const db = wx.cloud.database({});
    const cont = app.globalData.content;
    getApp().globalData.bindtap = 2;
    cont.skip(5).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data,
        })
      }
    })
  },
  dizhi: function () {
    this.setData({
      color2: '#00A2FF',
      color1: 'black',
      color3: 'black',
      color4: 'black',
      color5: 'black',
    })
    const db = wx.cloud.database({});
    const cont = db.collection('eas-dizhi');
    var choose = '地质地震灾害'
    this.setData({
      choose: '地质地震灾害'
    })
    app.globalData.content = db.collection('eas-dizhi');
    cont.skip(0).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data,
        })
      }
    })
  },
  haiyang: function () {
    this.setData({
      color3: '#00A2FF',
      color2: 'black',
      color1: 'black',
      color4: 'black',
      color5: 'black',
    })
    const db = wx.cloud.database({});
    const cont = db.collection('eas-haiyang');
    var choose = '海洋灾害'
    this.setData({
      choose: '海洋灾害'
    })
    app.globalData.content = db.collection('eas-haiyang');
    cont.skip(0).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data,
        })
      }
    })
  },
  shengwu: function () {
    this.setData({
      color4: '#00A2FF',
      color2: 'black',
      color3: 'black',
      color1: 'black',
      color5: 'black',
    })
    const db = wx.cloud.database({});
    const cont = db.collection('eas-shengwu');
    var choose = '生物水文灾害'
    this.setData({
      choose: '生物水文灾害'
    })
    app.globalData.content = db.collection('shengwu');
    cont.skip(0).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data,
        })
      }
    })
  },
  shengtai: function () {
    this.setData({
      color5: '#00A2FF',
      color2: 'black',
      color3: 'black',
      color4: 'black',
      color1: 'black',
    })
    const db = wx.cloud.database({});
    const cont = db.collection('eas-shengtai');
    var choose = '生态环境灾害'
    this.setData({
      choose: '生态环境灾害'
    })
    app.globalData.content = db.collection('eas-shengtai');
    cont.skip(0).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data,
        })
      }
    })
  },

  xuanye1: function () {
    const db = wx.cloud.database({});
    const cont = app.globalData.content;
    getApp().globalData.bindtap = 1;
    cont.skip(0).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data,
        })
      }
    })
  },
  xuanye2: function () {
    const db = wx.cloud.database({});
    const cont = app.globalData.content;
    getApp().globalData.bindtap = 2;
    cont.skip(5).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data,
        })
      }
    })
  },
  xuanye3: function () {
    const db = wx.cloud.database({});
    const cont = app.globalData.content;
    getApp().globalData.bindtap = 3;
    cont.skip(10).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data
        })
      }
    })
  },
  xuanye4: function () {
    const db = wx.cloud.database({});
    const cont = app.globalData.content;
    getApp().globalData.bindtap = 4;
    cont.skip(15).limit(5).get({
      //如果查询成功的话
      success: res => {
        this.setData({
          list: res.data
        })
      }
    })
  },
  xuanye5: function () {
    const db = wx.cloud.database({});
    const cont = app.globalData.content;
    getApp().globalData.bindtap = getApp().globalData.bindtap + 1;
    const bindtap = app.globalData.bindtap;
    cont.skip(bindtap * 5)
      .limit(5).get({
        //如果查询成功的话
        success: res => {
          this.setData({
            list: res.data
          })
        }
      })
  },
  navigateInto: function (e) {
    app.globalData.link = e.currentTarget.id
    wx.navigateTo({
      url: '/pages/dzdzzh/dzdzzh',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  qixiang: function () {
    // this.setData{
    //   list:
    // }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})